<template>
  <view class="container gray_bg personnel_info">
    <view class="cus_info_title">基本信息</view>
    <tm-form @submit="confirm" ref="formRef" v-model="form" transprent :label-width="300" :margin="[0, 0]" :padding="[0, 0]" :border="false">
      <tm-sheet :margin="[20, 20]" :round="3" :shadow="2">
        <tm-form-item label="人员姓名" field="real_name">
          <view class="form_static_label">{{form.real_name}}</view>
        </tm-form-item>
        <tm-form-item label="手机号" field="phone">
          <view class="form_static_label">{{form.phone}}</view>
        </tm-form-item>
        <tm-form-item label="职位" field="position">
          <view  class="form_static_label">{{form.position_text}}</view>
        </tm-form-item>
        <tm-form-item label="负责人" field="position">
          <view  class="form_static_label">{{form.is_leader === 1 ? '是' : '否'}}</view>
        </tm-form-item>
        <tm-form-item label="邮箱" field="email">
          <view class="form_static_label">{{form.email}}</view>
        </tm-form-item>
        <tm-form-item label="创建时间" field="email">
          <view class="form_static_label">{{form.created_at}}</view>
        </tm-form-item>
      </tm-sheet>
      <view class="cus_footer_btn">
        <tm-button _class="['footer_btn', 'footer_danger_btn']" outlined color="#EA0000" :margin="[10]" width="310" round="25" :shadow="0" size="normal" label="删除" @click="deletePerson"> </tm-button>
        <tm-button _class="['footer_btn']" :margin="[10]" round="25" :shadow="0" width="310" size="normal" label="修改" @click="editUser"> </tm-button>

      </view>
    </tm-form>
<!--     删除提示框 -->
    <tm-modal
        color="white"
        okColor="#fff"
        border="3"
        title="提示"
        v-model:show="visible"
        titleStyle="[{font-size: 18px;}]"
    >
      <template #default>
        <view class="content_text">
          <view>确认删除该人员信息吗？</view>
          <view>删除后将无法恢复</view>
        </view>
      </template>
      <template #button>
        <view class="modal_bottom_btn">
          <view class="modal_footer_btn modal_cancel_btn" @click="cancel">暂不</view>
          <view class="modal_footer_btn modal_sure_btn" @click="handleOk">确认</view>
        </view>
      </template>
    </tm-modal>
  </view>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import {addUser, deleteUser, getPositionList} from "@/api_request/api";
import { storeToRefs } from 'pinia'
import { useInfoStore } from '@/store/userInfo'

const userStore = useInfoStore()
const { userInfo } : any = storeToRefs(userStore)

//  根据参数判断  设置导航栏标题
const readonly = ref<boolean>(false)
const formRef = ref<any>(null)
const merchant_id = ref(userInfo.value.merchant_id || 12)//
const form = ref<any>({
  merchant_id: '', //租客id
  real_name: '',
  phone: '', //手机号
  email: '', //邮箱
  position: '', //职位
  id: ''
})
const visible = ref<boolean>(false)

onLoad(async (options) => {
  const userInfo = options.data ? JSON.parse(options.data) : {}
  form.value = userInfo
  console.log('jp======potions',options, options.data)
})
const deletePerson = async () => {
  visible.value = true
}
const cancel = () => {
  visible.value = false
}
const handleOk = async () => {
  const res: any = await deleteUser({id: form.value.id})
  visible.value = false
  if(res.code === 200) {
    uni.$showMsg('操作成功！')
    uni.navigateTo({url: `/subpkg/personnel/list`})
    return
  }
  uni.$showMsg(res.message)
}
const editUser = () => {
  const row = JSON.stringify(form.value)
  uni.navigateTo({url: `/subpkg/addUser/index?isEdit=true&row=${row}`})
}

</script>
<style lang="scss" scoped>
.personnel_info{
  height: 100%;
}
  .cus_footer_btn{
    display: flex;
    justify-content: space-between;
    padding-left: 20px;
    padding-right: 20px;
  }
  .content_text{
    padding-top:30px;
    text-align: center;
    line-height: 22px;
  }
</style>